import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mokeng/widgets/widgets.dart';

import 'logic.dart';
import 'widgets/index.dart';

class StoreView extends GetView<StoreController> {
  const StoreView({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        inputSearchWithCalender(),
        Expanded(
          child: Obx(() => controller.tabList.isEmpty
              ? const Center(child: Text("暂无数据"))
              : Column(
                  children: [
                    buildTabBar(controller.tabList.map<String>((element) => element['name']).toList(),
                        controller.tabController),
                    Expanded(child: _buildPageView()),
                  ],
                )),
        ),
      ],
    );
  }

  // 内容页
  Widget _buildPageView() {
    return TabBarView(
      controller: controller.tabController,
      children: controller.tabList.asMap().entries.map((entry) {
        return entry.value['type'] == 3 || entry.value['type'] == 0
            ? StoreRecommendView(value: entry.value, tag: entry.value['id'])
            : Center(child: Text('Tab ${entry.value['name']}'));
      }).toList(),
    );
  }
}
